﻿using Microsoft.AspNetCore.Mvc;
using Zhp.Api.Attributes;
using Zhp.IService.Sys;
using Zhp.Model.Common;
using Zhp.Model.Sys;

namespace Zhp.Api.Controllers.Sys
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiGroup(GroupName = ApiGroupEnum.Sys)]
    public class SysRoleMenuController : ControllerBase
    {
        protected readonly ISysRoleMenuService SysRoleMenu;

        public SysRoleMenuController(ISysRoleMenuService SysRoleMenu)
        {
            this.SysRoleMenu = SysRoleMenu;
        }

        [SeedButton("分配菜单", "角色列表", "角色管理", ApiGroupEnum.Sys)]
        [HttpGet("{roleId}")]
        public async Task<ListRet<RoleMenuModel>> Index(long roleId)
        {
            var (roleMenulist, menuList) = await SysRoleMenu.GetRoleMenu(roleId);
            
            return new ListRet<RoleMenuModel>
            {
                DataList = roleMenulist,
                DataExt = menuList
            };
        }

        [SeedButton("分配菜单:保存", "角色列表", "角色管理", ApiGroupEnum.Sys)]
        [HttpPost]
        public async Task<bool> Create(RoleMenuCreate create)
        {
            return await SysRoleMenu.Create(create);
        }
    }
}
